# -*- coding: UTF-8 -*-


from jsonrpc import RPC

import json

base_url = 'http://192.168.56.111:8069'

timeout = 50000


dbname = 'T1'
username = 'admin'
password = '123456'


rpc = RPC(base_url, timeout, dbname)


def test_user():
    rpc.login(username, password)
    so = rpc.env.model('res.users')
    ids = so.test()

    print(ids)


def test_so():
    rpc.login(username, password)
    so = rpc.env.model('sale.order')
    ids = so.search([])
    print(ids)
    res = so.name_get(ids)
    print('name get', res)
    res = so.read(ids, fields=['name'])
    print(res)
    res = so.search_read([], fields=['name'])
    print(res)


def test_customer_for_demo():
    rpc.login(username, password)
    so = rpc.env.model('res.partner.customer_for_demo')
    ids = so.search_read()

    print(ids)


def test_customer():
    rpc.login(username, password)
    so = rpc.env.model('res.partner.customer')
    ids = so.search_read()

    print(ids)


def test_prd():
    prd = rpc.env.model('product.product')
    ids = prd.search([('categ_id.group', '=', 'fapiao'),
                      ('id', '>', 100)], order='id')
    print(ids)
    prd.unlink(ids)
    # res = prd.read(ids, fields=['name', 'code'])
    # print(res)
    # for one in res:
    #     prd.write(one['id'], {
    #         'name': one['code'],
    #         'code': one['name']
    #     })

    # res = prd.read(ids, fields=['name', 'code'])
    # print(res)
    pass


test_user()
